<template>
  <div class="app-container">
    <div style="font-size:14px;color:red;text-align:center">*默认只查询当天的检查数据，如果要查询其他的，请选择范围查询</div>
    <br>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="医生工作量统计列表" name="first" >
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="医生姓名" prop="dName">
            <el-input
              v-model="queryParams.dName"
              placeholder="请输入医生姓名"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item label="接诊时间">
            <el-date-picker
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd hh:mm:ss"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="docterWorkList" @selection-change="" show-summary="true" >
          <el-table-column label="挂号ID" align="center" prop="regId" />
          <el-table-column label="医生编号" align="center" prop="dId" />
          <el-table-column label="医生姓名" align="center" prop="dName" />
          <el-table-column label="挂号费用" align="center" prop="regPrice" />
          <el-table-column label="患者姓名" align="center" prop="patiName"  />
          <el-table-column label="就诊时间" align="center" prop="regSdate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.regSdate) }}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    <br>
      <el-tab-pane label="总体工作量统计列表" name="second">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="医生姓名" prop="dName">
            <el-input
              v-model="queryParams.dName"
              placeholder="请输入医生姓名"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item label="接诊时间">
            <el-date-picker
              v-model="dateRangeS"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd hh:mm:ss"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="docterWorkSum" @selection-change="" show-summary="true" >
          <el-table-column label="医生编号" align="center" prop="dId" />
          <el-table-column label="医生姓名" align="center" prop="dName" />
          <el-table-column label="挂号总额" align="center" prop="regPrice" />
          <el-table-column label="接诊数量" align="center" prop="count"  />
        </el-table>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { listDocterWork, sumDocterWork,getPost, delPost, addPost, updatePost, exportPost } from "@/api/records/docterWork";

export default {
  name: "Post",
  data() {
    return {
        activeName: 'first',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
    //  single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
        //时间范围参数
      dateRange: [],
        dateRangeS:[],
      // 项目列表表格数据
        docterWorkList: [],
        docterWorkSum: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        dName: undefined,
          // beginTime:undefined,
          // endTime:undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        postName: [
          { required: true, message: "岗位名称不能为空", trigger: "blur" }
        ],
        postCode: [
          { required: true, message: "岗位编码不能为空", trigger: "blur" }
        ],
        postSort: [
          { required: true, message: "岗位顺序不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getSum();
    this.getDicts("sys_normal_disable").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    /** 查询检查项目列表 */
    getList() {
      this.loading = true;
        listDocterWork(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.docterWorkList = response.rows;
        this.loading = false;
      });
    },
      getSum(){
          this.loading = true;
          sumDocterWork(this.addDateRange(this.queryParams, this.dateRangeS)).then(response => {
              this.docterWorkSum = response.rows;
              this.loading = false;
          });
      },
    // 岗位状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
          regId: undefined,
          dId: undefined,
          dName:undefined,
          regPrice: undefined,
          patiName: undefined,
          regSdate: undefined,
          count: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
      /**总量统计搜索按钮操作*/
      handleQuerySum() {
          this.getSum();
      },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有岗位数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportPost(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
